--[[
    显示在玩家座位头像上的表情
]]--

local blaze = require "blaze"
local app = require "app"
local gamelib = require "club.threecard.gamelib"
local Emoji = require "club.threecard.gamelib.UI.Chat.Emoji"
local chat = gamelib.chat

local M = gamelib.ui.element()

function M:ctor()
    self.emoji = nil
    self.co = nil
end

function M:show(emoji_id)
    self:super("show")
    self:lazy("on_show", emoji_id)
end

function M:on_show(emoji_id)
    if self.co then
        self:stop_coroutine(self.co)
        self.co = nil
    end
    if self.emoji then
        if self.emoji.config.id == emoji_id then
            -- 表情和上次相同就不用重新加载了
        else
            self.emoji:release()
            self.emoji = Emoji.new_from_id(emoji_id)
        end
    else
        self.emoji = Emoji.new_from_id(emoji_id)
    end
    self.emoji:show()
    self.emoji:load()
    self.emoji:set_parent(self.parent)
    self.co = self:start_coroutine(function()
        self.app.coroutine.wait(3)
        self.emoji:hide()
    end)
end

function M:on_release()
    self:super("on_release")
    if self.emoji then
        self.emoji:release()
    end
end

return M